package com.blueocean_health.care.management.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.blueocean_health.care.management.common.LocalManager;
import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.domain.base.User;
import com.blueocean_health.care.management.domain.dto.ManagerDto;
import com.blueocean_health.care.management.domain.dto.PullDownDto;
import com.blueocean_health.care.management.domain.dto.UserDto;
import com.blueocean_health.care.management.em.LocalManagerType;
import com.blueocean_health.care.management.service.UserService;

/**
 * 负责人下拉框 接口    2017年8月22日15:37:01
 * @author wuyanli
 *
 */
@RestController
@RequestMapping("web/user")
public class UserController{
	
	@Resource
	private UserService userService;
	
	@Value("${service.address}")
	private String serviceAddress;

	/**
	 * 根据医院Id获取外勤人员信息  2017年8月31日15:18:10
	 * @param user
	 * @return
	 */
	@RequestMapping("getFieldWorker")
	public SysResult getFieldWorkerByHospital(){
		User user = LocalManager.getVal(LocalManagerType.USER_WEB);
		//根据医院Id获取外勤人员信息
//		List<PullDownDto> list = userService.getFieldWorkerByHospitalId(user.getHospitalId());
//		List<PullDownDto> list = userService.getFieldWorkerByHospitalId("1");
//		return SysResult.ok(0, "success", list);
		//根据医院Id获取所有负责人信息  2018年2月28日10:40:03
		List<PullDownDto> fieldWorkerByHospitalId = userService.getFieldWorkerByHospitalId(user.getHospitalId()+"");
		return SysResult.ok(0, "success", fieldWorkerByHospitalId);
	}
	/**
	 * 根据医院Id获取所有负责人信息 2017年8月22日16:49:58  资金管理专用
	 * @param user
	 * @return
	 */
	@RequestMapping("getManagerByHospital")
	public SysResult getManagerByHospital(){
		User user = LocalManager.getVal(LocalManagerType.USER_WEB);
//		List<ManagerDto> managerInfo = userService.getManagerByHospital("1");
		List<ManagerDto> managerInfo = userService.getManagerByHospital(user.getHospitalId());
		return SysResult.ok(0, "success", managerInfo);
	}
	
	@RequestMapping(value = "login")
	public SysResult login(@RequestBody(required = false) User user) {
		
		if(StringUtils.isEmpty(user.getUserName())){
			return SysResult.error(-1, "用户名不能为空");
		}else if(StringUtils.isEmpty(user.getPassword())){
			return SysResult.error(-1, "密码不能为空");
		}else{
			UserDto currentUserInfo = userService.getCurrentUserInfo(user);
			System.out.println(currentUserInfo);
			if(currentUserInfo==null){
				return SysResult.error(-1, "用户名或密码不正确");
			}
			return SysResult.ok(currentUserInfo);
		}
	}
	
}
